<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:h="http://java.sun.com/jsf/html" xmlns:pe="http://primefaces.org/ui/extensions"
                xmlns:util="http://java.sun.com/jsf/composite/util">

    <pe:importEnum type="md.mru.core.domains.type.NodeType" var="nodeType"/>

    <h:form id="tree_view_form">

        <!-- context menu for static_folder type tree nodes -->
        <p:contextMenu id="tree-context-menu-static-folder" for="tree_view" nodeType="#{nodeType.STATIC_FOLDER}">
            <p:menuitem value="Adauga" icon="ui-icon-plus" oncomplete="treeNodeDialog.show()"
                        update=":add_node_form"
                        actionListener="#{treeAdministrationBean.setupTreeNodeDialog('add')}"/>
        </p:contextMenu>

        <!-- context menu for folder type tree nodes -->
        <p:contextMenu id="tree-context-menu-folder" for="tree_view" nodeType="#{nodeType.FOLDER}">
            <p:menuitem value="Adauga" icon="ui-icon-plus" oncomplete="treeNodeDialog.show()"
                        update=":add_node_form"
                        actionListener="#{treeAdministrationBean.setupTreeNodeDialog('add')}"/>
            <p:menuitem value="Editeaza" icon="ui-icon-pencil" oncomplete="treeNodeDialog.show()"
                        update=":add_node_form"
                        actionListener="#{treeAdministrationBean.setupTreeNodeDialog('edit')}"/>
        </p:contextMenu>

        <!-- context menu for position type tree nodes -->
        <p:contextMenu id="tree-context-menu-position" for="tree_view" nodeType="#{nodeType.POSITION}">
            <p:menuitem value="Ataseaza persoana" icon="ui-icon-plus"
                        actionListener="#{orderAdministrationBean.initEmploymentOrderDialog}" process="@this"
                        oncomplete="PF('orderWV').show()" update=":order_dialog"/>
            <p:menuitem value="Editeaza" icon="ui-icon-pencil" oncomplete="treeNodeDialog.show()"
                        update=":add_node_form"
                        actionListener="#{treeAdministrationBean.setupTreeNodeDialog('edit')}"/>
        </p:contextMenu>

        <!-- context menu for attached_person type tree nodes -->
        <p:contextMenu id="tree-context-menu-attached" for="tree_view" nodeType="#{nodeType.ATTACHED_PERSON}">
            <p:menuitem value="Editeaza" icon="ui-icon-pencil" oncomplete="treeNodeDialog.show()"
                        update=":add_node_form"
                        actionListener="#{treeAdministrationBean.setupTreeNodeDialog('edit')}"/>
        </p:contextMenu>

        <!-- tree-view component-->
        <p:tree id="tree_view" var="node" dynamic="true" value="#{treeAdministrationBean.rootModel}"
                styleClass="tree-drag-drop-override  tree-view"
                selection="#{treeAdministrationBean.selectedTreeNode}"
                selectionMode="single" draggable="#{treeAdministrationBean.moveActivated}" droppable="true"
                dragdropScope="demo" dropRestrict="sibling" style="border: none;width :100%;">

            <p:ajax event="select" process="@this" update=":main_content" ignoreAutoUpdate="true"
                    listener="#{treeAdministrationBean.onNodeSelect}"/>
            <p:ajax event="dragdrop" process="@this" listener="#{treeAdministrationBean.onDragDrop}"
                    ignoreAutoUpdate="true"/>

            <ui:remove><!-- static_folder type tree nodes --></ui:remove>
            <p:treeNode icon="#{node.treeNodeType.nodeType.icon}" type="#{nodeType.STATIC_FOLDER}">
                <h:outputText value="#{node.name}" styleClass="tree-node-label"/>
            </p:treeNode>

            <ui:remove><!-- read_only type tree nodes --></ui:remove>
            <p:treeNode icon="#{node.treeNodeType.nodeType.icon}" type="#{nodeType.READ_ONLY}">
                <util:treeNodeLabelWrapper forId="tree_node_read_only" nodeVar="#{node}"/>
                <ui:include src="tree-node-list-content.xhtml"/>
            </p:treeNode>

            <ui:remove><!-- folder type tree nodes --></ui:remove>
            <p:treeNode icon="#{node.treeNodeType.nodeType.icon}" type="#{nodeType.FOLDER}">
                <util:treeNodeLabelWrapper forId="tree_node_folder" nodeVar="#{node}"/>
            </p:treeNode>

            <ui:remove><!-- position type tree nodes --></ui:remove>
            <p:treeNode icon="#{node.treeNodeType.nodeType.icon}" styleClass="free-position"
                        type="#{nodeType.POSITION}">
                <util:treeNodeLabelWrapper forId="tree_node_position" nodeVar="#{node}"/>
                <ui:include src="tree-node-list-content.xhtml"/>
            </p:treeNode>

            <ui:remove><!-- attached_person type tree nodes --></ui:remove>
            <p:treeNode icon="#{node.treeNodeType.nodeType.icon}" type="#{nodeType.ATTACHED_PERSON}">
                <util:treeNodeLabelWrapper forId="tree_node_attached_person" nodeVar="#{node}"/>
                <ui:include src="tree-node-list-content.xhtml"/>
            </p:treeNode>

        </p:tree>
    </h:form>
</ui:composition>